package com.glory.gloryquickui.viewmodel

import androidx.lifecycle.MutableLiveData
import com.glory.gloryquickui.base.BaseViewModel
import com.glory.gloryquickui.entity.BaseRequestBean
import com.glory.gloryquickui.entity.FieldBean
import com.glory.gloryquickui.entity.SingleChooseOptionsBean
import com.glory.gloryquickui.model.QuickUIRepository
import com.glory.gloryquickui.view.CheckBoxSelectController
import com.glory.gloryquickui.view.DropDowmSelectController
import com.glory.gloryquickui.view.RadioButtonSelectController
import com.glory.gloryquickui.view.ViewController
import com.glory.hiwork.mvvm.bean.CallObserveBean
import com.glory.hiwork.mvvm.bean.ToastMessageBean
import com.google.gson.Gson
import com.google.gson.JsonArray
import com.google.gson.JsonObject
import org.json.JSONArray
import org.json.JSONObject

/**
 * @author HX
 * @date 2021/4/20
 * @desc 业务逻辑
 */
class QuickUIViewModel : BaseViewModel() {

    var allComponents = mutableListOf<FieldBean>()
    val rewardRepository = QuickUIRepository()
    var controllerList = mutableListOf<ViewController<*>>()
    var controllerMapList = mutableMapOf<String, ViewController<*>>()
    var pageData = MutableLiveData<Map<String, String>>()
    var dynamicComponents = mutableListOf<FieldBean>()
    var pageJson = MutableLiveData<String>()
    var baseFormData: FieldBean? = null
    var deploymentName:String = "" //流程名称
    private fun getColumnValueMap(data: FieldBean): HashMap<String, String> {
        val paramsMap = HashMap<String, String>()
        if (data.config.tagIcon.equals("fieldset")) {
            data.formQueryCondition.forEach { query ->
                pageData.value!!.forEach {
                    if (it.key == query.key) {
                        paramsMap[it.key] = it.value
                    }
                }
            }
        } else if (data.config.tagIcon.equals("table")) {
            for (dataTableBean in data.config.dataParamsTable) {
                if (dataTableBean.type == "1" && !(dataTableBean.value.isEmpty())) {
                    paramsMap[dataTableBean.code] = dataTableBean.value
                } else if (dataTableBean.type == "2") {
                    pageData.value!!.forEach {
                        if (it.key == dataTableBean.value && !(it.value.isEmpty())) {
                            paramsMap[dataTableBean.code] = it.value
                        }
                    }
                }
            }
        }else if (data.config.tagIcon.equals("select") || data.config.tagIcon.equals("radio") || data.config.tagIcon.equals("checkbox")) {
            data.config.option.dataTable.params.forEach {
                if (it.type == "1" && !(it.value.isEmpty())) {
                    paramsMap[it.code] = it.value
                } else if (it.type == "2") {
                    pageData.value!!.forEach { page->
                        if (page.key == it.value && !(page.value.isEmpty())) {
                            paramsMap[it.code] = page.value
                        }
                    }
                }
            }
        }
        return paramsMap
    }

    private fun getThirdColumnValueMap(data: FieldBean): HashMap<String, String> {
        val paramsMap = HashMap<String, String>()
        if (data.config.tagIcon.equals("table")) {
            data.config.baseData.params.forEach {
                if (it.type == "1" && !(it.value.isEmpty())) {
                    paramsMap[it.code.replaceFirst("#", "")] = it.value
                } else if (it.type == "2") {
                    pageData.value!!.forEach { page ->
                        if (it.value == page.key && !(page.value.isEmpty())) {
                            paramsMap[it.code.replaceFirst("#", "")] = page.value
                        }
                    }
                }
            }
        }else if(data.config.tagIcon.equals("select") || data.config.tagIcon.equals("radio") || data.config.tagIcon.equals("checkbox")){
            data.config.option.packageInfo.params.forEach {
                if (it.type == "1" && !(it.value.isEmpty())) {
                    paramsMap[it.code.replaceFirst("#", "")] = it.value
                } else if (it.type == "2") {
                    pageData.value!!.forEach { page ->
                        if (it.value == page.key && !(page.value.isEmpty())) {
                            paramsMap[it.code.replaceFirst("#", "")] = page.value
                        }
                    }
                }
            }
        }


        return paramsMap
    }


    fun searchData() {
        dynamicComponents.forEach {
            val conditionMap = getColumnValueMap(it)
            conditionMap.forEach {
                if (it.value.isEmpty()) {
                    defUI.toastEvent.value = ToastMessageBean("查询条件不能为空", false)
                    return
                }
            }
            if(it.config.dataType.equals("third")) {

                launchOnlyResult({
                    val json = rewardRepository.getDataByThird(
                        BaseRequestBean(
                            conditionMap,
                            "",
                            "",
                            1,
                            99,
                            0,
                            false,
                            it.config.baseData.id.toInt(),
                            getThirdColumnValueMap(it)
                        )
                    )
                    if (it.config.tagIcon == "table") {
                        val map = pageData.value!!.toMutableMap()
                        map[it.vModel] = json
                        pageData.value = map
                    } else {
                        val jsonArray = JSONArray(json)
                        if (jsonArray.length() > 0) {
                            val jsonObject = jsonArray.getJSONObject(0)
                            val map = pageData.value!!.toMutableMap()
                            map.forEach { entity ->
                                if (jsonObject.has(entity.key)) {
                                    map[entity.key] = jsonObject.getString(entity.key)
                                }
                            }
                            pageData.value = map
                        }
                    }
                })

            }else{

                launchOnlyResult({
                    val json = rewardRepository.getDataByOneTable(
                        BaseRequestBean(
                            conditionMap,
                            it.config.dataConnectId, it.config.dataSourceTable[1], 1, 99, 0, false
                        )
                    )
                    if (it.config.tagIcon == "table") {
                        val map = pageData.value!!.toMutableMap()
                        map[it.vModel] = json
                        pageData.value = map
                    } else {
                        val jsonArray = JSONArray(json)
                        if (jsonArray.length() > 0) {
                            val jsonObject = jsonArray.getJSONObject(0)
                            val map = pageData.value!!.toMutableMap()
                            map.forEach { entity ->
                                if (jsonObject.has(entity.key)) {
                                    map[entity.key] = jsonObject.getString(entity.key)
                                }
                            }
                            pageData.value = map
                        }
                    }
                })

            }
        }
    }

    fun searchForm(formId: String) {
        launchOnlyResult({
            val baseBean = rewardRepository.getFormJsonById(formId)
            if (baseBean.result.code == "200" && baseBean.body != null) {
                pageJson.value = baseBean.body.formJson
            } else {
                defUI.toastEvent.value = ToastMessageBean("请求错误，请重试", false)
            }
        })
    }

    fun saveData() {
        val dataMap = pageData.value
        var type = 1
        if (dataMap!!["ID"]!!.isEmpty()) {
            type = 0
        }
        val requestMap = HashMap<String, String>()
        dynamicComponents.forEach { dataValue ->
            if (dataValue.config.tagIcon == "fieldset") {
                dataValue.config.dataParamsTable.forEach { queryParams ->
                    pageData.value!!.forEach {
                        if (queryParams.columnName == it.key) {
                            requestMap[it.key] = it.value
                        }
                    }
                }
            }
        }
        launchOnlyResult({
            val baseBean = rewardRepository.operateDataByOneTable(
                BaseRequestBean(
                    requestMap,
                    baseFormData!!.config.dataConnectId,
                    baseFormData!!.config.dataSourceTable[1], 1, 99, type, false
                )
            )
            if (baseBean.result.code == "200" && baseBean.body != null) {
                defUI.toastEvent.value = ToastMessageBean(baseBean.result.message, true)
            } else {
                defUI.toastEvent.value = ToastMessageBean("请求错误，请重试", false)
            }
        })
    }


    fun deleteData(vModel: String, ID: String, postion: Int) {
        var type = 2
        val requestMap = HashMap<String, String>()
        dynamicComponents.forEach { dataValue ->
            if (dataValue.vModel == vModel) {
                requestMap["ID"] = ID
                launchOnlyResult({
                    val baseBean = rewardRepository.operateDataByOneTable(
                        BaseRequestBean(
                            requestMap,
                            dataValue!!.config.dataConnectId,
                            dataValue!!.config.dataSourceTable[1], 1, 99, type, false
                        )
                    )
                    if (baseBean.result.code == "200" && baseBean.body != null) {
                        defUI.toastEvent.value = ToastMessageBean(baseBean.result.message, true)
                        defUI.callObserve.value = CallObserveBean(2,postion)
                    } else {
                        defUI.toastEvent.value = ToastMessageBean("请求错误，请重试", false)
                    }
                })
            }
        }
    }

    fun deleteThirdData(vModel: String, ID: String, postion: Int){
        dynamicComponents.forEach { dataValue ->
            if (dataValue.vModel == vModel) {
                val js = JSONObject()
                js.put("ID", ID)
                val bean = BaseRequestBean()
                bean.datasourceId = dataValue.config.dataConnectId
                bean.id = dataValue.config.baseData.id.toInt()
                bean.dataTableName = dataValue.config.baseData.dataName
                bean.columnValueMapList = arrayListOf(js)
                bean.tableNameList = dataValue.config.baseData.tableList as ArrayList<String>
                launchOnlyResult({
                    val baseBean = rewardRepository.operateDeleteHandleTable(
                        bean
                    )
                    if (baseBean.result.code == "200") {
                        defUI.toastEvent.value = ToastMessageBean(baseBean.result.message, true)
                        defUI.callObserve.value = CallObserveBean(2, postion)
                    } else {
                        defUI.toastEvent.value = ToastMessageBean("请求错误，请重试", false)
                    }
                })
            }
        }
    }

    fun searchInterfaceData(data: FieldBean){
        val map = pageData.value!!.toMutableMap()
        val requestMap = HashMap<String, String>()
        try {
            val jsonObj = JSONObject(data.config.request.json)
            val keys = jsonObj.keys()
            while (keys.hasNext()){
                val key = keys.next()
                val value = jsonObj.getString(key)
                if(!value.contains("$")){
                    requestMap[key] = value
                }
            }
        } catch (e: Exception) {
            defUI.toastEvent.value = ToastMessageBean("解析错误，请重试", false)
            return
        }

        data.config.request.variableList.forEach {
            if(it.path.size == 1){
                requestMap[it.path.get(0)] = map[it.key]!!
            }
        }

        launchOnlyResult({
            if (data.config.requestMethod == "GET") {
                val json = rewardRepository.getDataByInterfaceGet(
                    requestMap, data.config.requestUrl
                )
                val resultJson = JSONObject(json)
                if (resultJson.getJSONObject("result").getString("code") == "200") {
                    val map = pageData.value!!.toMutableMap()
                    data.config.response.variableList.forEach {
                        var bodyJsonObject:JSONObject = resultJson
                        var bodyString:String = ""
                        for (i in it.path.indices) {
                            if(i != (it.path.size - 1)) {
                                bodyJsonObject = bodyJsonObject.getJSONObject(it.path[i])
                            }else{
                                bodyString = bodyJsonObject.getString(it.path[i])
                            }
                        }
                        map[it.key] = bodyString
                    }
                    pageData.value = map
                    defUI.toastEvent.value = ToastMessageBean(resultJson.getJSONObject("result").getString("message"), true)
                } else {
                    defUI.toastEvent.value = ToastMessageBean("请求错误，请重试", false)
                }
            } else {
                val json = rewardRepository.getDataByInterfacePost(
                    requestMap, data.config.requestUrl
                )
                val resultJson = JSONObject(json)
                if (resultJson.getJSONObject("result").getString("code") == "200") {
                    val map = pageData.value!!.toMutableMap()
                    data.config.response.variableList.forEach {
                        var bodyJsonObject:JSONObject = resultJson
                        var bodyString:String = ""
                        for (i in it.path.indices) {
                            if(i != (it.path.size - 1)) {
                                bodyJsonObject = bodyJsonObject.getJSONObject(it.path[i])
                            }else{
                                bodyString = bodyJsonObject.getString(it.path[i])
                            }
                        }
                        map[it.key] = bodyString
                    }
                    pageData.value = map
                    defUI.toastEvent.value = ToastMessageBean(resultJson.getJSONObject("result").getString("message"), true)
                } else {
                    defUI.toastEvent.value = ToastMessageBean("请求错误，请重试", false)
                }
            }
        })
    }

    fun searchDictionaryInfo(data: FieldBean){
        val requestMap = HashMap<String, Any>()
        requestMap["tags"] = arrayListOf<String>()
        val pageJson = JsonObject()
        pageJson.addProperty("pageNo",1)
        pageJson.addProperty("pageSize",10000)
        requestMap["pager"] = pageJson
        val dataDictionaryJson = JsonObject()
        dataDictionaryJson.addProperty("dataType",data.config.option.dictType)
        requestMap["dataDictionary"] = dataDictionaryJson
        launchOnlyResult({
            val baseBean = rewardRepository.operateDictionaryList(
                requestMap
            )
            if (baseBean.result.code == "200") {

                if(data.config.tagIcon == "select") {

                    val vc = controllerMapList.get(data.config.formId) as DropDowmSelectController
                    var optionList: ArrayList<SingleChooseOptionsBean.Option> = arrayListOf()
                    var stringList: ArrayList<String> = arrayListOf()
                    if (baseBean.body.records!!.size < 0) {
                        defUI.toastEvent.value = ToastMessageBean("暂未查询到数据", false)
                        return@launchOnlyResult
                    }
                    val arrayJs = JSONArray(baseBean.body.records?.get(0)?.dataDictionarys)
                    for (i in 0 until arrayJs.length()) {
                        val option = SingleChooseOptionsBean.Option()
                        if (data?.config?.option?.dependObject!!.isEmpty()) {
                            if(data.config.option.label.isEmpty()) {
                                stringList.add(arrayJs.getJSONObject(i).getString("dataName"))
                                option.label = arrayJs.getJSONObject(i).getString("dataName")
                            }else{
                                stringList.add(arrayJs.getJSONObject(i).getString(data?.config?.option.label))
                                option.label = arrayJs.getJSONObject(i).getString(data?.config?.option.label)
                            }
                            if(data.config.option.value.isEmpty()) {
                                option.value =
                                    arrayJs.getJSONObject(i).getString("dataId")
                            }else{
                                option.value =
                                    arrayJs.getJSONObject(i).getString(data?.config?.option.value)
                            }
                            if(data.config.option.parentId.isEmpty()) {
                                option.parentId =
                                    arrayJs.getJSONObject(i).getString("ext2")
                            }else{
                                option.parentId =
                                    arrayJs.getJSONObject(i).getString(data?.config?.option.parentId)
                            }

                            optionList.add(option)
                        } else {
                            if (pageData.value?.get(data?.config?.option?.dependObject) == arrayJs.getJSONObject(
                                    i
                                ).getString(data?.config?.option.parentId)
                            ) {
                                if(data.config.option.label.isEmpty()) {
                                    stringList.add(arrayJs.getJSONObject(i).getString("dataName"))
                                    option.label = arrayJs.getJSONObject(i).getString("dataName")
                                }else{
                                    stringList.add(arrayJs.getJSONObject(i).getString(data?.config?.option.label))
                                    option.label = arrayJs.getJSONObject(i).getString(data?.config?.option.label)
                                }
                                if(data.config.option.value.isEmpty()) {
                                    option.value =
                                        arrayJs.getJSONObject(i).getString("dataId")
                                }else{
                                    option.value =
                                        arrayJs.getJSONObject(i).getString(data?.config?.option.value)
                                }
                                if(data.config.option.parentId.isEmpty()) {
                                    option.parentId =
                                        arrayJs.getJSONObject(i).getString("ext2")
                                }else{
                                    option.parentId =
                                        arrayJs.getJSONObject(i).getString(data?.config?.option.parentId)
                                }

                                optionList.add(option)
                            }
                        }
                    }
                    vc.updateDropDowmData(optionList, stringList)

                }else if(data.config.tagIcon == "radio"){

                    val vc = controllerMapList.get(data.config.formId) as RadioButtonSelectController
                    var optionList: ArrayList<SingleChooseOptionsBean.Option> = arrayListOf()
                    val arrayJs = JSONArray(baseBean.body.records?.get(0)?.dataDictionarys)
                    for (i in 0 until arrayJs.length()) {
                        val option = SingleChooseOptionsBean.Option()
                        if (data?.config?.option?.dependObject!!.isEmpty()) {
                            if(data.config.option.label.isEmpty()) {
                                option.label = arrayJs.getJSONObject(i).getString("dataName")
                            }else{
                                option.label = arrayJs.getJSONObject(i).getString(data?.config?.option.label)
                            }
                            if(data.config.option.value.isEmpty()) {
                                option.value =
                                    arrayJs.getJSONObject(i).getString("dataId")
                            }else{
                                option.value =
                                    arrayJs.getJSONObject(i).getString(data?.config?.option.value)
                            }
                            if(data.config.option.parentId.isEmpty()) {
                                if(arrayJs.getJSONObject(i).has("ext2")) {
                                    option.parentId =
                                        arrayJs.getJSONObject(i).getString("ext2")
                                }
                            }else{
                                option.parentId =
                                    arrayJs.getJSONObject(i).getString(data?.config?.option.parentId)
                            }
                            optionList.add(option)
                        }
                    }
                    vc.updateRadioButtonData(optionList)

                }else if(data.config.tagIcon == "checkbox"){

                    val vc = controllerMapList.get(data.config.formId) as CheckBoxSelectController
                    var optionList: ArrayList<SingleChooseOptionsBean.Option> = arrayListOf()
                    val arrayJs = JSONArray(baseBean.body.records?.get(0)?.dataDictionarys)
                    for (i in 0 until arrayJs.length()) {
                        val option = SingleChooseOptionsBean.Option()
                        if (data?.config?.option?.dependObject!!.isEmpty()) {
                            if(data.config.option.label.isEmpty()) {
                                option.label = arrayJs.getJSONObject(i).getString("dataName")
                            }else{
                                option.label = arrayJs.getJSONObject(i).getString(data?.config?.option.label)
                            }
                            if(data.config.option.value.isEmpty()) {
                                option.value =
                                    arrayJs.getJSONObject(i).getString("dataId")
                            }else{
                                option.value =
                                    arrayJs.getJSONObject(i).getString(data?.config?.option.value)
                            }
                            if(data.config.option.parentId.isEmpty()) {
                                if(arrayJs.getJSONObject(i).has("ext2")) {
                                    option.parentId =
                                        arrayJs.getJSONObject(i).getString("ext2")
                                }
                            }else{
                                option.parentId =
                                    arrayJs.getJSONObject(i).getString(data?.config?.option.parentId)
                            }
                            optionList.add(option)
                        }
                    }
                    vc.updateCheckBoxData(optionList)

                }

            } else {
                defUI.toastEvent.value = ToastMessageBean("请求错误，请重试", false)
            }
        })

    }

    fun searchDataTableInfo(data: FieldBean){
        val conditionMap = getColumnValueMap(data)
        launchOnlyResult({
            val json = rewardRepository.getDataByOneTable(
                BaseRequestBean(
                    conditionMap,
                    data.config.option.dataTable.dataConnectId, data.config.option.dataTable.dataSource[1], 1, 999, 0, false
                )
            )
            if(data.config.tagIcon == "select") {

                val vc = controllerMapList.get(data.config.formId) as DropDowmSelectController
                var optionList: ArrayList<SingleChooseOptionsBean.Option> = arrayListOf()
                var stringList: ArrayList<String> = arrayListOf()
                val arrayJs = JSONArray(json)
                for (i in 0 until arrayJs.length()) {
                    val option = SingleChooseOptionsBean.Option()
                    if (data?.config?.option?.dependObject!!.isEmpty()) {
                        stringList.add(
                            arrayJs.getJSONObject(i).getString(data?.config?.option.label)
                        )
                        option.label =
                            arrayJs.getJSONObject(i).getString(data?.config?.option.label)
                        option.value =
                            arrayJs.getJSONObject(i).getString(data?.config?.option.value)
                        optionList.add(option)
                    } else {
                        if (pageData.value?.get(data?.config?.option?.dependObject) == arrayJs.getJSONObject(
                                i
                            ).getString(data?.config?.option.parentId)
                        ) {
                            stringList.add(
                                arrayJs.getJSONObject(i).getString(data?.config?.option.label)
                            )
                            option.label =
                                arrayJs.getJSONObject(i).getString(data?.config?.option.label)
                            option.value =
                                arrayJs.getJSONObject(i).getString(data?.config?.option.value)
                            optionList.add(option)
                        }
                    }
                }
                vc.updateDropDowmData(optionList, stringList)

            }else if (data.config.tagIcon == "radio"){

                val vc = controllerMapList.get(data.config.formId) as RadioButtonSelectController
                var optionList: ArrayList<SingleChooseOptionsBean.Option> = arrayListOf()
                val arrayJs = JSONArray(json)
                for (i in 0 until arrayJs.length()) {
                    val option = SingleChooseOptionsBean.Option()
                    if (data?.config?.option?.dependObject!!.isEmpty()) {
                        option.label =
                            arrayJs.getJSONObject(i).getString(data?.config?.option.label)
                        option.value =
                            arrayJs.getJSONObject(i).getString(data?.config?.option.value)
                        optionList.add(option)
                    }
                }
                vc.updateRadioButtonData(optionList)

            }else if(data.config.tagIcon == "checkbox"){

                val vc = controllerMapList.get(data.config.formId) as CheckBoxSelectController
                var optionList: ArrayList<SingleChooseOptionsBean.Option> = arrayListOf()
                val arrayJs = JSONArray(json)
                for (i in 0 until arrayJs.length()) {
                    val option = SingleChooseOptionsBean.Option()
                    if (data?.config?.option?.dependObject!!.isEmpty()) {
                        option.label =
                            arrayJs.getJSONObject(i).getString(data?.config?.option.label)
                        option.value =
                            arrayJs.getJSONObject(i).getString(data?.config?.option.value)
                        optionList.add(option)
                    }
                }
                vc.updateCheckBoxData(optionList)

            }


        })
    }

    fun searchDataThirdInfo(data: FieldBean){

            launchOnlyResult({
                val json = rewardRepository.getDataByThird(
                    BaseRequestBean(
                        HashMap<String, String>(),
                        "",
                        "",
                        1,
                        9999,
                        0,
                        false,
                        data.config.option.packageInfo.id,
                        getThirdColumnValueMap(data)
                    )
                )
                if(data.config.tagIcon == "select") {

                    val vc = controllerMapList.get(data.config.formId) as DropDowmSelectController
                    var optionList: ArrayList<SingleChooseOptionsBean.Option> = arrayListOf()
                    var stringList: ArrayList<String> = arrayListOf()
                    val arrayJs = JSONArray(json)
                    for (i in 0 until arrayJs.length()) {
                        val option = SingleChooseOptionsBean.Option()
                        if (data?.config?.option?.dependObject!!.isEmpty()) {
                            stringList.add(
                                arrayJs.getJSONObject(i).getString(data?.config?.option.label)
                            )
                            option.label =
                                arrayJs.getJSONObject(i).getString(data?.config?.option.label)
                            option.value =
                                arrayJs.getJSONObject(i).getString(data?.config?.option.value)
                            optionList.add(option)
                        } else {
                            if (pageData.value?.get(data?.config?.option?.dependObject) == arrayJs.getJSONObject(
                                    i
                                ).getString(data?.config?.option.parentId)
                            ) {
                                stringList.add(
                                    arrayJs.getJSONObject(i).getString(data?.config?.option.label)
                                )
                                option.label =
                                    arrayJs.getJSONObject(i).getString(data?.config?.option.label)
                                option.value =
                                    arrayJs.getJSONObject(i).getString(data?.config?.option.value)
                                optionList.add(option)
                            }
                        }
                    }
                    vc.updateDropDowmData(optionList, stringList)

                }else if (data.config.tagIcon == "radio"){

                    val vc = controllerMapList.get(data.config.formId) as RadioButtonSelectController
                    var optionList: ArrayList<SingleChooseOptionsBean.Option> = arrayListOf()
                    val arrayJs = JSONArray(json)
                    for (i in 0 until arrayJs.length()) {
                        val option = SingleChooseOptionsBean.Option()
                        if (data?.config?.option?.dependObject!!.isEmpty()) {
                            option.label =
                                arrayJs.getJSONObject(i).getString(data?.config?.option.label)
                            option.value =
                                arrayJs.getJSONObject(i).getString(data?.config?.option.value)
                            optionList.add(option)
                        }
                    }
                    vc.updateRadioButtonData(optionList,)

                }else if(data.config.tagIcon == "checkbox"){

                    val vc = controllerMapList.get(data.config.formId) as CheckBoxSelectController
                    var optionList: ArrayList<SingleChooseOptionsBean.Option> = arrayListOf()
                    val arrayJs = JSONArray(json)
                    for (i in 0 until arrayJs.length()) {
                        val option = SingleChooseOptionsBean.Option()
                        if (data?.config?.option?.dependObject!!.isEmpty()) {
                            option.label =
                                arrayJs.getJSONObject(i).getString(data?.config?.option.label)
                            option.value =
                                arrayJs.getJSONObject(i).getString(data?.config?.option.value)
                            optionList.add(option)
                        }
                    }
                    vc.updateCheckBoxData(optionList)

                }
            })
    }

    fun syncExecuteWorkflowByName(){
        val requestMap = HashMap<String, Any>()
        requestMap["deploymentName"] = deploymentName
        requestMap["syncStatus"] = false
        val pageJson = JsonObject()
        allComponents.forEach { all ->
            if(all.config.tagIcon == "button"){
                return@forEach
            }
            if(all.vColumn.isEmpty()) {
                pageJson.addProperty(all.vModel, pageData.value!![all.vModel])
            }else{
                pageJson.addProperty(all.vColumn,pageData.value!![all.vModel])
            }
        }
        val jsonArray = JsonArray()
        jsonArray.add(pageJson)
        val fieldsetJson = JsonObject()
        fieldsetJson.add(baseFormData?.config?.dataSourceTable!![1],jsonArray)
        requestMap["requestMap"] = fieldsetJson
        launchOnlyResult({
            val json = rewardRepository.syncExecuteWorkflowByName(
                requestMap
            )
            defUI.callObserve.value = CallObserveBean(3,json)
        })

    }
}